﻿using Abp.AutoMapper;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Ixyu.Authorization;
using Ixyu.Base.Dictionaries.Authorization;
using Ixyu.Base.Dictionaries.Mapper;
using Ixyu.Health.Mapper;
using Ixyu.Work.Mapper;

namespace Ixyu
{
    [DependsOn(
        typeof(IxyuCoreModule), 
        typeof(AbpAutoMapperModule))]
    public class IxyuApplicationModule : AbpModule
    {
        public override void PreInitialize()
        {
            Configuration.Authorization.Providers.Add<IxyuAuthorizationProvider>();
        }

        public override void Initialize()
        {
            var thisAssembly = typeof(IxyuApplicationModule).GetAssembly();

            IocManager.RegisterAssemblyByConvention(thisAssembly);

            Configuration.Modules.AbpAutoMapper().Configurators.Add(
                // Scan the assembly for classes which inherit from AutoMapper.Profile
                cfg =>
                {
                    cfg.AddProfiles(thisAssembly);
                    AbpDictionaryMapper.CreateMappings(cfg);
                    DailyLifeMapper.CreateMappings(cfg);
                    WorkItemMapper.CreateMappings(cfg);
                }
            );

            Configuration.Authorization.Providers.Add<AbpDictionaryAuthorizationProvider>();
           
        }
    }
}
